<template>
  <div class="my-tag">
    <input
      ref="inp"
      v-if="isShowEdit"
      class="input"
      v-focus
      v-model="tempText"
      @keyup.enter="handleEnter"
      type="text"
      placeholder="输入标签"
      @blur="isShowEdit = false"
    />
    <div v-else class="text" @dblclick="showEdit">茶具</div>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: String,
      required: true,
    },
  },

  data() {
    return {
      isShowEdit: false,
      tempText: "茶具",
    };
  },
  methods: {
    // 双击的时候 展示输入框
    showEdit() {
      this.isShowEdit = true;
    },
    handleEnter(e) {
      // console.log(e.target);
      this.$emit("input", e.target.value); 
      this.isShowEdit = false;
    },
  },
};
</script>

<style scoped lang="less">
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>